/**
 * @运用指针修改数值
 *
 * @author	 wangshikun <wangshikun2010@gmail.com>
 * @copyright	(c) 2012 wangshikun <wangshikun2010@gmail.com>
 * @license	http://www.opensource.org/licenses/mit-license.php The MIT License
 * @package	default
 * @subpackage	default
 */

#include <stdio.h>

// 声明两个不变的整型指针参数，两个指针不会被函数所改变
void exchange(int const *p1, int const *p2);

int main(void) {
	int i1 = -5, i2 = 66, *p1 = &i1, *p2 = &i2;

	printf("i1 = %d, i2 = %d", i1, i2);

	exchange(p1, p2);
	printf("i1 = %d, i2 = %d\n", i1, i2);

	exchange(&i1, &i2);
	printf("i1 = %d, i2 = %d\n", i1, i2);

	return 0;
}

// 交换两个指针参数所指向的整型变量的值
void exchange(int const *p1, int const *p2) {
	int temp;

	// 交换两值
	temp = *p1;
	*p1 = *p2;
	*p2 = temp;
}
